import http from '@/http';
import type {Post, PostParams, ResponseData} from '@/types/interface';

const postApi = {
    // 发布帖子
    publishPost: (data: PostParams): Promise<ResponseData<{ postId: number }>> => {
        return http.post('/post/publish', data);
    },

    // 获取帖子列表（分页）
    getPostList: (page: number, size: number): Promise<ResponseData<{
        list: Post[];
        total: number;
    }>> => {
        return http.get(`/post/list?page=${page}&size=${size}`);
    },

    // 获取帖子详情
    getPostDetail: (postId: number): Promise<ResponseData<Post>> => {
        return http.get(`/post/detail?postId=${postId}`);
    },

    // 获取用户发布的帖子
    getUserPosts: (userId: number, page: number, size: number): Promise<ResponseData<{
        list: Post[];
        total: number;
    }>> => {
        return http.get(`/post/user?userId=${userId}&page=${page}&size=${size}`);
    },

    // 删除帖子
    deletePost: (postId: number): Promise<ResponseData<boolean>> => {
        return http.delete(`/post/delete?postId=${postId}`);
    }
};

export default postApi;